<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	
</style>
<script type="text/javascript">
	$(function() {
		$('#tag_datagrid_toolbar').toolbar({buttons:[
           	{name:'add_tag',iconCls:'icon-add',text:'添加标签'},
      	],handler:handler});
		
	    $('#article_datagrid').datagrid({
	    	url:'/article/info/page',
    		pagination:true,
    		singleSelect:true,
    		striped:true,
    		fit:true,
    		fitColumns:true,
    		toorbar:'#toolbar_articleTable',
    		columns:[[
    			{field:'id',title:'编号'},
    			{field:'articleTitle',title:'文章标题'},
        		{field:'userName',title:'作者'},
        		{field:'articleType',title:'类型',formatter:function(v,r,i){
        			var type ="";
        			if(r.articleType == "1"){type ="文章"}else if(r.articleType == "3"){type ="音频"}else if(r.articleType == "5"){type="视频"}else if(r.articleType == "7"){type="话题pk"}
        			return type;
        		}},
        		{field:'markPublish',title:'发布标记'},
        		{field:'countView',title:'浏览量'},
        		{field:'countPraise',title:'点赞量'},
        		{field:'countShare',title:'分享量'},
        		{field:'countCollect',title:'收藏量'},
        		{field:'markAudit',title:'审核标记'},
        		{field:'enabled',title:'是否可用',formatter:function(v,r,i){
        			var enab = '否';
        			if(r.enabled){
        				enab = '是'
        			}
        			return enab;
        		}},
    		]],
    		view: detailview,
    	    detailFormatter: function(rowIndex, rowData){
    	        return '<table><tr>' +
    	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
    	                '</tr></table>';
    	    },
    	    onSelect:loadTags
		 });
	    $('#tag_datagrid').datagrid({
			singleSelect:true,
			fitColumns:true,
			fit:true,
			method:'get',
			columns:[[
				{field:'ck',checkbox:true},
				{field:'tagName',title:'标签名称'},
				{field:'action',title:'操作',formatter:function(v,r,i){
					return '<a href="#" onclick="removeTag('+r.id+');">移除</a>';
				}}
			]],
		 });
	    
	    
	    function loadTags(index,row){
	    	var param = {};
	    	param.articleId = row.id;
	    	param.tagType = "3";
	    	$('#tag_datagrid').datagrid({ 
	    		queryParams: param,
	    		url:"findByArticleId"
	    	});   
	    }
	    
		 //过滤条件参数
		function getItem(){
			var userName = $.trim($("#search_user").textbox("getValue"));
			var articleTitle = $.trim($("#search_articleTitle").textbox("getValue"));
			var articleType = $.trim($("#search_articleType").combobox("getValue"));
			var enabled = $.trim($("#search_enabled").combobox("getValue"));
			var searchItem = {};
			if(userName.length>0){
				searchItem.userName=userName;
			}
			if(articleTitle.length>0){
				searchItem.articleTitle=articleTitle;
			}
			if(articleType.length>0){
				searchItem.articleType=articleType;
			}
			if(enabled.length>0){
				searchItem.enabled=enabled;
			}
			return searchItem;
		}
		function handler() {
			switch(this.name) {
				case 'add_tag': toAdd();break;
				case 'save_category': saveCategory();break;
			}
		}
		function toAdd() {
			var row = $('#article_datagrid').datagrid("getSelected");
			if(row != null && row != ""){
				var articleId = row.id;
				console.log(articleId);
				show({code:'tag_info_add',title:'添加标签信息',iconCls:'icon-add',uri:'edit?id='+ articleId,width:500,height:390,
					options : {
						success : function(data) { 
							loadTags('',row);
						}
					}
				});
			}else{
				top.$ok('请选择文章');
			}
		}

	
	$("#a_searchTag").click(function(){
		reloadDate();
	});
	$("#a_clearn").click(function(){
		resetData();
	});
		
		function reloadDate(){
			var item = getItem();
			$('#article_datagrid').datagrid({ queryParams: item});   //点击搜索
		}
		function resetData(){
			$("#search_user").textbox("setValue","");
			$("#search_articleTitle").textbox("setValue","");
			$("#search_articleType").combobox("setValue","");
			$("#search_enabled").combobox("setValue","");
			reloadDate();
		}
		
	});
	//查看详细
	function detail(id){
		console.log("详细");
	}
	function disbled(id){
		var parms = {};
		parms.id = id;
		parms.enabled = true;
		$.post('updateEnabled',parms,function(r){
			if(r.code>0){
				$('#article_datagrid').datagrid('reload'); 
			};
		},'json');
	}
	//更新可用标记
	function enabled(id){
		var parms = {};
		parms.id = id;
		parms.enabled = false;
		$.post('updateEnabled',parms,function(r){
			if(r.code>0){
				$('#article_datagrid').datagrid('reload'); 
			};
		},'json');
	}
	//移除标签
	function removeTag(id){
		 var article = $('#article_datagrid').datagrid("getSelected");
		 var parms = {};
		 parms.articleId = article.id;
		 parms.tagId = id;
		 $.post('deleteByTagIdAndArticleId',parms,function(r){
				if(r.code>0){
					top.$prompt('删除成功');
					var param = {};
			    	param.articleId = article.id;
			    	param.tagType = "3";
			    	$('#tag_datagrid').datagrid({ 
			    		queryParams: param,
			    		url:"findByArticleId"
			    	}); 
					
				};
			},'json');
	 }
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
	    		<legend>过滤条件</legend>
	    		<table style="width:100%">
	    			<tr>
	    				<td>文章标题:<input id="search_articleTitle" class="easyui-textbox" data-options="prompt:'请输入文章名称'" ></td>
	    				<td>文章作者:<input id="search_user" class="easyui-textbox" data-options="prompt:'请输入作者'" ></td>
	    				<td>
	    					文章类型:
	    					<select id="search_articleType" class="easyui-combobox" data-options="width:60,panelHeight:100">
	    						<option></option>
	    						<option value="1">文章</option>
	    						<option value="3">音频</option>
	    						<option value="5">视频</option>
	    						<option value="7">话题pk</option>
	    					</select>
	    				</td>
	    				<td>
	    					是否可用:
	    					<select id="search_enabled" class="easyui-combobox" name="enabled" data-options="width:50,panelHeight:60">
	    						<option> </option>
	    						<option value="1">是</option>
	    						<option value="0">否</option>
	    					</select>
	    				</td>
	    				<td><a id="a_searchTag" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
	    				<td>
	    					<a id="a_clearn" class="easyui-linkbutton" iconCls="icon-undo">清除</a>
	    				</td>
	    			</tr>
	    		</table>
	  		</fieldset>
		</div>
		<div data-options="region:'east',split:true,collapsible:false" title="所属标签" style="width:25%;padding-bottom: 33px">
			<div id="tag_datagrid_toolbar" class="toolbar" ></div>
			<table id="tag_datagrid" class="easyui-datagrid"></table>
		</div>
  		<div data-options="region:'center',border:true" title="文章信息" style="width:75%;padding-bottom: 33px">
  			<table id="article_datagrid"></table>
		</div>
	</div>
</body>
</html>